﻿Public Class ArgumentTypeTemplateSelector
    Inherits DataTemplateSelector

    Public Overrides Function SelectTemplate(item As Object, container As DependencyObject) As DataTemplate
        Dim element As FrameworkElement = TryCast(container, FrameworkElement)
        If element IsNot Nothing AndAlso item IsNot Nothing AndAlso TypeOf item Is ArgumentBaseVm Then
            Dim arg As ArgumentBaseVm = CType(item, ArgumentBaseVm)
            Select Case arg.Type
                Case "Bit"
                    Return CType(element.FindResource("BitArgDataTemplate"), DataTemplate)
                Case "CharCode"
                    Return CType(element.FindResource("CharCodeArgDataTemplate"), DataTemplate)
                Case "ColorNumber"
                    Return CType(element.FindResource("ColorNumberArgDataTemplate"), DataTemplate)
                Case "List", "Lookup"
                    Return CType(element.FindResource("ListArgDataTemplate"), DataTemplate)
                Case "Material"
                    Return CType(element.FindResource("MaterialArgDataTemplate"), DataTemplate)
                Case Else
                    Return CType(element.FindResource("StringArgDataTemplate"), DataTemplate)
            End Select
        Else
            Return Nothing
        End If

    End Function
End Class

